package fr.seba.wawadroid.proxyweb.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import fr.seba.wawadroid.proxyweb.to.WawaPost;

public class CategoryPageParser {

	private static final Pattern PATTERN_GROUP_POST = Pattern.compile("<tr class=\"inew\">(.*?)</tr>",Pattern.DOTALL);
	
	public static List<WawaPost> getPosts(String pageContent){
		
		List<WawaPost> wawaPosts = new ArrayList<WawaPost>();
		
		Matcher matcherPostGroup = PATTERN_GROUP_POST.matcher(pageContent);
		int groupCount;
		while(matcherPostGroup.find()){
			groupCount = matcherPostGroup.groupCount();
			if(groupCount > 0){
				for (int i = 1; i <= groupCount; i++) {
					PostParser.getPost(matcherPostGroup.group(i));				
				}
			}
		}		
		
		return wawaPosts;
		
	}
	
	
}
